package org.usmile.algorithms.huawei.acm;

import java.util.*;

// https://blog.csdn.net/qq_34465338/article/details/128732631
public class _垃圾信息拦截 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<int[]> messageList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            messageList.add(new int[]{from, to});
        }

        int A = sc.nextInt();

        Set<Integer> sendSet = new HashSet<>();
        Set<Integer> receiveSet = new HashSet<>();
        Map<Integer, Integer> sendCount = new HashMap<>();
        Map<Integer, Integer> receiveCount = new HashMap<>();
        int sendMailsNum = 0;
        int getMailsNum = 0;
        for (int[] message : messageList) {
            if (message[0] == A) {
                sendSet.add(message[1]);
                sendMailsNum++;
                sendCount.put(message[1], sendCount.getOrDefault(message[1], 0) + 1);
            } else if (message[1] == A) {
                getMailsNum++;
                receiveSet.add(message[0]);
                receiveCount.put(message[0], receiveCount.getOrDefault(message[0], 0) + 1);
            }
        }

        boolean isTrash = false;
        sendSet.removeAll(receiveSet);
        int L = sendSet.size();
        int M = sendMailsNum - getMailsNum;
        if (L > 5) {
            isTrash = true;
        } else if (M > 10) {
            isTrash = true;
        } else {
            for (Map.Entry<Integer, Integer> map : sendCount.entrySet()) {
                int getId = map.getKey();
                int send = map.getValue();
                if (receiveCount.containsKey(getId)) {
                    if (send - receiveCount.get(getId) > 5) {
                        isTrash = true;
                        break;
                    }
                }
            }
        }

        System.out.println(isTrash + " " + L + " " + M);
    }
}
